#include <stdio.h>

// const int maxLen=30;

struct Tree
{
    struct Tree * left;
    struct Tree * right;
    int number;
};

int searchIndex(int* array,int start,int end,int value)
{
    for(int i=start;i<end;i++)
    {
        if(array[i]==value)
        {
            return i;
        }
    }
}

int main(){
    int n;
    int *array1,*array2;
    scanf("%d",&n);
    array1=new int[n];
    array2=new int[n];
    int i;
    for(i=0;i<n;i++)
    {
        scanf("%d",&array1[i]);
    }
    for(i=0;i<n;i++)
    {
        scanf("%d",&array2[i]);
    }

    Tree** queue=new Tree*[n];
    int* startArray=new int[n];
    int* endArray=new int[n];
    int start=0,end=1;

    Tree* root=new Tree;
    root->number=array1[0];
    queue[0]=root;
    startArray[0]=0;
    endArray[0]=n;

    //还原二叉树
    i=1;
    while (start<end)
    {
        Tree* tree=queue[start];
        if(startArray[start]<endArray[start])
        {
            int nowSt=startArray[start];
            int nowEnd=endArray[start];
            int index=searchIndex(array2,nowSt,nowEnd,tree->number);
            if(nowSt<index)
            {
                Tree* left=new Tree;
                left->number=array1[i];
                tree->left=left;
                i++;
               
                queue[end]=left;
                startArray[end]=start;
                endArray[end]=index;
                end++;
            }

            if(index<nowEnd-1)
            {
                Tree* right=new Tree;
                right->number=array1[i];
                tree->right=right;
                i++;
               
                queue[end]=right;
                startArray[end]=index+1;
                endArray[end]=nowEnd;
                end++;
            }
            
        }
        start++;
    }


    //
    queue[0]=root;
    startArray[0]=0; 
    start=0;
    end=1;
    i=0;

    int *printArray=new int[n];
    while(end>0)
    {
        Tree* tree=queue[start];
        if(startArray[start]==0)
        {
            printArray[i]=tree->number;
            i++;
            startArray[start]++;
        }

        if(startArray[start]==1&&tree->left){
            queue[end]=tree->left;
            startArray[end]=0; 
        }
        

    }
    



    delete array1;
    delete array2;
    delete printArray;
    return 0;
}